require 'apr.mime'
require 'moonunit'

test_mime = moonunit.TestCase:new()

function test_mime:test_unparse_headers()
    local h = {Subject = 'Test Subject', From = 'Test From <test@example.com>'}
    
    assert(apr.mime.unparse_headers(h) == 'Subject: Test Subject\r\nFrom: Test From <test@example.com>')
end

function test_mime:test_unparse_multiline_headers()
    local h = {Subject = 'This should be a multi-line header', From = 'Not this'}
    local header_str = '\r\n' .. apr.mime.unparse_headers(h, 16) .. '\r\n'
    assert(header_str:find('\r\nFrom: Not this\r\n', 1, true) ~= nil)
    assert(header_str:find('\r\nSubject: This \r\n', 1, true) ~= nil)
    assert(header_str:find('\r\n should be a m\r\n', 1, true) ~= nil)
    assert(header_str:find('\r\n ulti-line hea\r\n', 1, true) ~= nil)
    assert(header_str:find('\r\n der\r\n', 1, true) ~= nil)
end
